/*
 * ImageUtil.cpp
 *
 *  Created on: Jul 12, 2009
 *      Author: kurt
 */

#include "ImageUtil.h"
#include <pspgu.h>
#include <stdlib.h>
using namespace std;
using namespace objdraw;

int ImageUtil::getNextPower2(int width)
{
	int b = width;
	int n;
	for (n = 0; b != 0; n++) b >>= 1;
	b = 1 << n;
	if (b == 2 * width) b >>= 1;
	return b;
}

const u8 ImageUtil::pixelWidths[] = 
{
	16,	//GU_PSM_5650
	16,	//GU_PSM_5551
	16,	//GU_PSM_4444
	32,	//GU_PSM_8888
	4,	//GU_PSM_T4
	8	//GU_PSM_T8
};
const u8 ImageUtil::paletteSizes[] =
{
	0,
	0,
	0,
	0,
	4,	//GU_PSM_T4
	8	//GU_PSM_T8
};
bool ImageUtil::auto_swizzle = false;

Image * ImageUtil::loadImageFile(string file, DrawingCanvas * canvas)
{
	return loadImageFile(file,GU_PSM_8888,auto_swizzle,false,canvas);
}
Image * ImageUtil::loadImageFile(std::string file, PixelFormat pixelFormat, DrawingCanvas * canvas)
{
	return loadImageFile(file,pixelFormat,auto_swizzle,false,canvas);
}
Image * ImageUtil::loadImageFile(std::string file, PixelFormat pixelFormat, bool in_vram, DrawingCanvas * canvas)
{
	return loadImageFile(file,pixelFormat,auto_swizzle,in_vram,canvas);
}
Image * ImageUtil::loadImageFile(std::string file, PixelFormat pixelFormat, bool swizzle, bool in_vram, DrawingCanvas * canvas)
{
	if(is_png(file))
		return loadImageFilePNG(file,pixelFormat,swizzle,in_vram,canvas);
//	TODO add more here
	return NULL;
}
